package tt;





import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;

public class ConsumerTest {
	@Test
	public void testConsumer() throws JMSException{
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		Connection con = factory.createConnection();
		con.start();
		Session sen = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
		Topic topic = sen.createTopic("aa");
		MessageConsumer consumer = sen.createConsumer(topic);
		TextMessage msg = (TextMessage)consumer.receive();
		System.out.println(msg.getText());
		con.close();
	}

	public static void main(String[] args) throws JMSException, InterruptedException {
		// TODO Auto-generated method stub
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		Connection con = factory.createConnection();
		con.start();
		Session se = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
		Queue queue = se.createQueue("tt");
		MessageConsumer consumer = se.createConsumer(queue);
		while(true){
			TextMessage msg = (TextMessage)consumer.receive();
			msg.acknowledge();
			System.out.println(msg.getText());
			Thread.sleep(1000);
		}
		
		
	}

}
